<?php
class handle_upload
{	
	
	public function upload_img($infofile,$dirname,$filename,$maxsize='5242880')
	{
		if ((($infofile["type"] == "image/gif") || 
			($infofile["type"] == "image/jpeg") ||
			($infofile["type"] == "image/x-png") || 
			($infofile["type"] == "image/bmp") || 
			($infofile["type"] == "image/pjpeg")) && 
			($infofile["size"] < $maxsize)){
			
			if ($infofile["error"] > 0)
            {
				return  $infofile["error"];
			}
            else {

				$arrtag = explode('.',$infofile["name"]);
                $ImgName = pathinfo($infofile["name"]);
				$tmp = $filename.'.'.$ImgName['extension'];
				move_uploaded_file($infofile["tmp_name"], $dirname.$tmp);
				return $tmp;
			}
		}else{
			return false;
		}
	}
	
	public function upload_file($infofile,$dirname,$filename,$maxsize='5242880')
	{
		
		$str = '7z,aiff,asf,avi,bmp,csv,doc,docx,fla,flv,gif,gz,gzip,jpeg,jpg,mid,mov,mp3,mp4,mpc,mpeg,mpg,ods,odt,pdf,png,ppt,pptx,pxd,qt,ram,rar,rm,rmi,rmvb,rtf,sdc,sitd,swf,sxc,sxw,tar,tgz,tif,tiff,txt,vsd,wav,wma,wmv,xls,xlsx,zip';
		$arr = explode(",",$str);
		$arrtag = explode('.',$infofile["name"]);
		$sl = end($arrtag);
		if(in_array($arr, $sl, true)){
		
			if (($infofile["type"] != "") && ($infofile["size"] < $maxsize)){
				
				if ($infofile["error"] > 0){
					return  $infofile["error"];
				
				} else {
					$tmp = $filename.'.'.$infofile["name"];
					move_uploaded_file($infofile["tmp_name"], $dirname.$tmp);
					return $tmp;
				}
			}else{
				return false;
			}
		}else{
				return false;
		}
	}
   
 }
 
?>